package com.sxt.bus.controller;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.sxt.bus.BUSConstast.BUSConstast;
import com.sxt.bus.domain.Goods;
import com.sxt.bus.domain.Inport;
import com.sxt.bus.domain.Provider;
import com.sxt.bus.service.GoodsService;
import com.sxt.bus.service.InportService;
import com.sxt.bus.service.ProviderService;
import com.sxt.bus.vo.GoodsVo;
import com.sxt.bus.vo.InportVo;
import com.sxt.bus.vo.ProviderVo;
import com.sxt.sys.SYSConstast.SYSConstast;
import com.sxt.sys.utils.ResultObj;
import com.sxt.sys.utils.WebUtils;
import com.sxt.bus.utils.DataGridView;

@RestController
@RequestMapping("inport")
public class InportController {
	
	
	@Autowired
	private InportService inportService;
	
	
	@Autowired
	private GoodsService goodsService;
	
	@RequestMapping("loadAllInport")
	public DataGridView loadAllInport(InportVo inportVo) {
		
		return inportService.queryAllInport(inportVo);
	}
	
	@RequestMapping("deleteInport")
	public ResultObj deleteInport(InportVo inportVo) {
		Integer code=1;
		String msg="";
		try {
			inportService.deleteInport(inportVo.getId());
			return new ResultObj(200, SYSConstast.OPERATE_DELETE_SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new ResultObj(-1, SYSConstast.OPERATE_DELETE_ERROR);
	}
	
	@RequestMapping("updateInport")
	public ResultObj updateInport(InportVo inportVo) {
		Integer code=1;
		String msg="";
		try {
			Integer info = inportService.updateInport(inportVo);
			code = info;
			msg = info > 0 ?BUSConstast.UPDATE_LOGININFOR_TRUE:BUSConstast.UPDATE_LOGININFOR_FALSE;
		} catch (Exception e) {
			code = 0;
			msg = BUSConstast.UPDATE_LOGININFOR_FALSE;
		}
		return new ResultObj(code , msg);
	}
	
	
	@RequestMapping("addInport")
	public ResultObj addInport(InportVo inportVo) {
		try {
			inportVo.setInporttime(new Date());
			inportVo.setOperateperson(WebUtils.getCurrentUser().getName());
			this.inportService.addInport(inportVo);
			return new ResultObj(1, BUSConstast.OPERATE_ADD_SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new ResultObj(-1, BUSConstast.OPERATE_ADD_ERROR);
	}
	
	
	@RequestMapping("loadAllgoods")
	public List<Goods> loadAllgoods(GoodsVo goodsVo){
		
		return goodsService.loadAllgoods(goodsVo);
	}
	
}
